﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FernUniHagen.CompilerExtension.DataStructures;
using Roslyn.Compilers.Common;
using Roslyn.Compilers.CSharp;
using FernUniHagen.CompilerExtension.Functions;
using FernUniHagen.CompilerExtension.Adaptor;

namespace FernUniHagen.CompilerExtension.Converter
{
    public class FieldDeclarationConverter : NodeConverterFactory
    {
        /// <summary>
        /// R-VDecl1 && R-VDecl2
        /// @TODO: Lokale Variablen müssen deklariert werden können
        /// @TEXT: Regel für string a,b muß berücksichtigt werden
        /// </summary>
        /// <returns></returns>
        public override CommonSyntaxNode Convert()
        {
            return null;
            //var declaration = SyntaxElementFactory.GetConverter(Node);
            //return declaration.ConvertToMutiplicity();
            //var fieldSyntax = Utilities.CastNode<FieldDeclarationSyntax>(Node);

            //var declaration = DeclarationTarget.GetDeclaration(Node);
            //GenericNameSyntax genericType = null;
            //AttributeType attrType = AttributeType.None;
            //declaration.GetMultiplicityAttribute(out attrType, out genericType);

            //if (attrType == AttributeType.Any)
            //{
            //    //Convert the decleration site
            //    VariableDeclarationSyntax newDeclaration = fieldSyntax.Declaration.WithType(genericType);
            //    FieldDeclarationSyntax newField = fieldSyntax.WithDeclaration(newDeclaration);
            //    VariableDeclarationSyntax variableDecleration2= newField.Declaration.WithVariables(new SeparatedSyntaxList<VariableDeclaratorSyntax>() );
            //    newField = newField.WithDeclaration(variableDecleration2);
            //    SeparatedSyntaxList<VariableDeclaratorSyntax> decleratorSyntaxes = new SeparatedSyntaxList<VariableDeclaratorSyntax>(); ;
            //    //Build up the initializer site
            //    foreach (var declerationSyntax in fieldSyntax.Declaration.Variables)
            //    {
            //        EqualsValueClauseSyntax oldInitializer = declerationSyntax.Initializer;
            //        if (oldInitializer != null) continue;
            //        //TODO: public string _email, test; doesnot work
            //        ExpressionSyntax initializerExpression = Syntax.ParseExpression(string.Format(" new {0}()", genericType.ToString()));
            //        EqualsValueClauseSyntax newInitializer = Syntax.EqualsValueClause(initializerExpression);
            //        var decleratorSyntax = declerationSyntax.WithInitializer(newInitializer);
            //        decleratorSyntaxes = decleratorSyntaxes.Add(decleratorSyntax);

            //    }
            //    VariableDeclarationSyntax variableDecleration = newField.Declaration.WithVariables(decleratorSyntaxes);
            //    variableDecleration = variableDecleration.WithLeadingTrivia(fieldSyntax.GetLeadingTrivia());
            //    newField = newField.WithDeclaration(variableDecleration);
            //    return newField;
            //}
            //return fieldSyntax;
        }
    }
}